source 'https://github.com/CocoaPods/Specs.git'

platform :ios, '10.0'
inhibit_all_warnings!
use_frameworks!
workspace 'Canary'

# Class to encapsulate environment variables and provide convenience methods to
# convert the ENV value string to its appropriate type
class MyEnv
	TRUTHY_VALUES = %w(t true yes y 1).freeze

	attr_reader :value
	
	def initialize(name)
		@value = ENV[name].to_s.downcase
	end

	def to_boolean
		return true if TRUTHY_VALUES.include?(value.to_s)
		return false
	end
end

# Pods available to all targets in Canary.xcworkspace
pod 'LoremIpsum'

# Firebase must be available to all targets to avoid CocoaPods pulling in two
# different revisions of the implicit dependency GoogleUtilities.framework
# since 'MoPub-AdMob-Adapters' has a hard version dependency.
pod 'Firebase'
pod 'Firebase/Analytics'

# CocoaPods does not support the ability to include the same pod
# in different targets using different pathing. To support the
# varied needs of CI and local development, the pathing to the
# MoPub owned and operated pods are configured using environment
# variables.
mediation_path           = MyEnv.new("DEVELOPMENT_MOPUB_MEDIATION_REPO_PATH").value
mediation_remote         = MyEnv.new("DEVELOPMENT_MOPUB_MEDIATION_REPO_REMOTE").value
mediation_branch         = MyEnv.new("DEVELOPMENT_MOPUB_MEDIATION_REPO_BRANCH").value
use_production_mediation = MyEnv.new("USE_PRODUCTION_MOPUB_MEDIATION").to_boolean
use_production_sdk       = MyEnv.new("USE_PRODUCTION_MOPUB_SDK").to_boolean

# MoPub SDK
if use_production_sdk
	pod 'mopub-ios-sdk'
else
	pod 'mopub-ios-sdk', :path => '../'
end

# Network mediation adapters
if Dir.exists?(mediation_path) && !use_production_mediation
    # Use local mediation adapters first if available
    pod 'MoPub-AdColony-Adapters', :path => mediation_path
    pod 'MoPub-AdMob-Adapters', :path => mediation_path
    pod 'MoPub-Applovin-Adapters', :path => mediation_path
    pod 'MoPub-Chartboost-Adapters', :path => mediation_path
    pod 'MoPub-FacebookAudienceNetwork-Adapters', :path => mediation_path
    pod 'MoPub-IronSource-Adapters', :path => mediation_path
    pod 'MoPub-Mintegral-Adapters', :path => mediation_path
    pod 'MoPub-TapJoy-Adapters', :path => mediation_path
    pod 'MoPub-UnityAds-Adapters', :path => mediation_path
    pod 'MoPub-Verizon-Adapters', :path => mediation_path
    pod 'MoPub-Vungle-Adapters', :path => mediation_path
elsif mediation_remote != nil && !mediation_remote.to_s.empty? && !use_production_mediation
    # If local mediation adapters are not available, use pre-release remote and branch
    # Default to master branch if branch is not available
    branch = "master"
    if mediation_branch != nil && !mediation_branch.to_s.empty?
    	branch = mediation_branch
    end
    pod 'MoPub-AdColony-Adapters', :git => mediation_remote, :branch => branch
    pod 'MoPub-AdMob-Adapters', :git => mediation_remote, :branch => branch
    pod 'MoPub-Applovin-Adapters', :git => mediation_remote, :branch => branch
    pod 'MoPub-Chartboost-Adapters', :git => mediation_remote, :branch => branch
    pod 'MoPub-FacebookAudienceNetwork-Adapters', :git => mediation_remote, :branch => branch
    pod 'MoPub-IronSource-Adapters', :git => mediation_remote, :branch => branch
    pod 'MoPub-Mintegral-Adapters', :git => mediation_remote, :branch => branch
    pod 'MoPub-TapJoy-Adapters', :git => mediation_remote, :branch => branch
    pod 'MoPub-UnityAds-Adapters', :git => mediation_remote, :branch => branch
    pod 'MoPub-Verizon-Adapters', :git => mediation_remote, :branch => branch
    pod 'MoPub-Vungle-Adapters', :git => mediation_remote, :branch => branch
else
    # Use production if `use_production_mediation` is set to `true`, or if other methods fail
    pod 'MoPub-AdColony-Adapters'
    pod 'MoPub-AdMob-Adapters'
    pod 'MoPub-Applovin-Adapters'
    pod 'MoPub-Chartboost-Adapters'
    pod 'MoPub-FacebookAudienceNetwork-Adapters'
    pod 'MoPub-IronSource-Adapters'
    pod 'MoPub-Mintegral-Adapters'
    pod 'MoPub-TapJoy-Adapters'
    pod 'MoPub-UnityAds-Adapters'
    pod 'MoPub-Verizon-Adapters'
    pod 'MoPub-Vungle-Adapters'
end

# AppStore target.
target 'AppStore Application' do
    # Pods for 'AppStore Application'
end

# Internal target
target 'Internal Application' do
    # Pods for 'Internal Application'
    
    target 'CanaryUnitTests' do
        # Unit test target won't be able to link without inheriting the search paths
        inherit! :search_paths
    end
end
